﻿'   
'
'   g10EXETryItVB -               Copyright (C) 2011 PH Informática, SA.
'
'   This program is free software: you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the  Free Software Foundation, either version 3 of the  License,  or
'   (at your option) any later version.
'
'   This  program  is distributed in  the hope that it will  be  useful,
'   but  WITHOUT  ANY  WARRANTY; without even the  implied  warranty  of
'   MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR  PURPOSE.  See  the
'   GNU General Public License for more details.
'
'   You  should have received  a copy of  the GNU General Public License
'   along with this program. If not, see <http://www.gnu.org/licenses/>.
'
'

Module basModule

    ' TokenID de utilização do serviço
    Public sApiTokenID As String = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"

    ' SessionID identificação da sessão, deve ser gerado de cada vez que uma nova sessão
    ' se inicia ou sempre que se achar necessário.
    Public sSessionID As String = System.Guid.NewGuid.ToString

    ' Ligação ao webService
    Public myWs As New g10WSTryIt.g10TryItSoapClient

    ' ActualView
    Public oActualView As g10WSTryIt.g10MapView

    Public bLoading As Boolean = False

    ' Função que retorna imagem do mapa
    Public Function GetMapa(ByVal dCentroX As Double, ByVal dCentroY As Double, ByVal lEscala As Long, ByVal lImageWidth As Long, ByVal lImageHeight As Long) As System.Drawing.Image

        bLoading = True

        Dim oImage As System.Drawing.Image
        Dim bImageMapa() As Byte
        Dim oMemStream As System.IO.MemoryStream

        Try

            ' Invicação do método do webService
            bImageMapa = myWs.GetMapa(sApiTokenID, sSessionID, dCentroX, dCentroY, lEscala, lImageWidth, lImageHeight, False)

            ' Tranformação do array de bytes em Imagem
            oMemStream = New System.IO.MemoryStream(bImageMapa, 0, bImageMapa.Length)
            oMemStream.Write(bImageMapa, 0, bImageMapa.Length)
            oImage = System.Drawing.Image.FromStream(oMemStream, True)

            oActualView = myWs.getActualView(sApiTokenID, sSessionID)

            Return oImage

        Catch ex As Exception

            MsgBox(ex.ToString, , "Aviso! Algo não correu muito bem...")
            Return Nothing

        Finally

            bLoading = False

        End Try

    End Function

    Public Class ListItem
        Private _name As String
        Private _key As String
        Private _object As Object

        Public Sub New(ByVal p_name As String, ByVal p_key As String, ByRef p_object As Object)
            _name = p_name
            _key = p_key
            _object = p_object
        End Sub

        Public Function Key() As String
            Return _key
        End Function

        Public Function Name() As String
            Return _name
        End Function

        Public Overrides Function ToString() As String
            Return _name
        End Function

        Public Function [Object]() As Object
            Return _object
        End Function

    End Class

End Module
